package SwingView.Assignment;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.jdesktop.swingx.JXDatePicker;

import JDBC.StudentAssignmentActivities;
import SwingController.ALDownloadFile;
import SwingController.CmsPresenter;
import SwingModel.CmsAssignment;
import SwingModel.CmsAssignmentSubmission;
import SwingView.CmsContentPanelModel;
import SwingView.CmsTimeSelector;
import SwingView.Assignment.CmsCPAsgmEdit.AddFileActionListener;
import SwingView.Assignment.CmsCPAsgmEdit.FileEntry;

import javax.swing.BoxLayout;

public class CmsCPAsgmViewStudent  extends CmsContentPanelModel{
	

	private final JPanel jpContent;
	private JTextArea jtfTitle;
	private JTextArea jtfDescription;
	private List<FileButton> listOfFilePanel;
	
	private CmsAssignment asgm;
	private CmsAssignmentSubmission asgmSub;
	private JTextArea jtfAvaiDate;
	private JTextArea jtfDueDate;
	private JTextArea jtfPostedDate;
	private JTextArea jtfExpDate;
	private JTextArea jtfWeight;
	private JPanel jpFiles;
	private JPanel jpSubmission;
	
	
	public CmsCPAsgmViewStudent(){
		listOfFilePanel = new ArrayList();
		
		//helper panel to center the title panel
		JPanel jp = new JPanel();
		jp.setOpaque(false);
		jp.setPreferredSize(new Dimension(650, 30));
		jp.setBorder(BorderFactory.createEmptyBorder());
		GridBagLayout gbl_jp = new GridBagLayout();
		jp.setLayout(gbl_jp);
		
		//content panel
		jpContent = new JPanel();
		GridBagLayout gbl_jpContent = new GridBagLayout();
		gbl_jpContent.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0};
		gbl_jpContent.columnWeights = new double[]{1.0, 0.0};
		jpContent.setLayout(gbl_jpContent);
		jpContent.setOpaque(false);

		//Set up the scroll bar
		JScrollPane scroll = new JScrollPane(jpContent);
		
		//main Scroll bar
		scroll.setBorder(BorderFactory.createEmptyBorder());
		scroll.setOpaque(true);
		scroll.setPreferredSize(new Dimension(650,450));
		scroll.setBackground(Color.WHITE);

		//set up main panel and add components
		setLayout(new BorderLayout());
		setOpaque(false);
		add(jp,BorderLayout.NORTH);//Add title People
		
		//instantiate Quiz title
		JLabel jlAsgmComposerTitle = new JLabel("Assignment View");
		jlAsgmComposerTitle.setFont(jlAsgmComposerTitle.getFont().deriveFont(20.0f).deriveFont(Font.BOLD));
		jlAsgmComposerTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 10, 8));
		GridBagConstraints gbc_jlQuizComposerTitle = new GridBagConstraints();
		gbc_jlQuizComposerTitle.gridwidth = 2;
		gbc_jlQuizComposerTitle.gridx = 0;
		gbc_jlQuizComposerTitle.gridy = 0;
		jp.add(jlAsgmComposerTitle, gbc_jlQuizComposerTitle);

		add(scroll,BorderLayout.WEST);//Add People List
		
		//_________________________________________________________
		//TITLE:
		
		JLabel jlTitle = new JLabel("Title: ");
		jlTitle.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_jlTitle = new GridBagConstraints();
		gbc_jlTitle.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_jlTitle.insets = new Insets(0, 40, 5, 5);
		gbc_jlTitle.gridx = 0;
		gbc_jlTitle.gridy = 0;
		jpContent.add(jlTitle, gbc_jlTitle);
		
		jtfTitle = new JTextArea();
		jtfTitle.setToolTipText("Please enter the assignment title");
		jtfTitle.setBorder(BorderFactory.createEmptyBorder());
		jtfTitle.setEditable(false);
		GridBagConstraints gbc_jtfTitle = new GridBagConstraints();
		gbc_jtfTitle.insets = new Insets(0, 0, 5, 40);
		gbc_jtfTitle.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_jtfTitle.weightx = 1.0;
		gbc_jtfTitle.gridx = 1;
		gbc_jtfTitle.gridy = 0;
		gbc_jtfTitle.fill = GridBagConstraints.HORIZONTAL;
		jpContent.add(jtfTitle, gbc_jtfTitle);
		
		//_________________________________________________________
		//DESCRIPTION:

		
		JLabel jlDescription = new JLabel("Description: ");
		jlDescription.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_jlDescription = new GridBagConstraints();
		gbc_jlDescription.insets = new Insets(0, 40, 5, 5);
		gbc_jlDescription.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_jlDescription.gridx = 0;
		gbc_jlDescription.gridy = 1;
		jpContent.add(jlDescription, gbc_jlDescription);
		
		jtfDescription = new JTextArea();
		jtfDescription.setLineWrap(true);
		jtfDescription.setWrapStyleWord(true);
		jtfDescription.setEditable(false);
		GridBagConstraints gbc_jspDescription = new GridBagConstraints();
		gbc_jspDescription.insets = new Insets(0, 0, 30, 40);
		gbc_jspDescription.fill = GridBagConstraints.HORIZONTAL;
		gbc_jspDescription.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_jspDescription.gridx = 1;
		gbc_jspDescription.gridy = 1;
		gbc_jspDescription.weightx = 1.0;
		jpContent.add(jtfDescription, gbc_jspDescription);
		
		JLabel lblPostedDate = new JLabel("Posted Date:");
		lblPostedDate.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_lblPostedDate = new GridBagConstraints();
		gbc_lblPostedDate.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_lblPostedDate.insets = new Insets(0, 40, 5, 5);
		gbc_lblPostedDate.gridx = 0;
		gbc_lblPostedDate.gridy = 2;
		jpContent.add(lblPostedDate, gbc_lblPostedDate);
		
		jtfPostedDate = new JTextArea();
		GridBagConstraints gbc_jtfPostedDate = new GridBagConstraints();
		gbc_jtfPostedDate.insets = new Insets(0, 0, 5, 40);
		gbc_jtfPostedDate.fill = GridBagConstraints.BOTH;
		gbc_jtfPostedDate.gridx = 1;
		gbc_jtfPostedDate.gridy = 2;
		jpContent.add(jtfPostedDate, gbc_jtfPostedDate);
		
		//_________________________________________________________
		//DUE DATE:
		JLabel lblDueDate = new JLabel("Due Date:");
		lblDueDate.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		GridBagConstraints gbc_lblDueDate = new GridBagConstraints();
		gbc_lblDueDate.fill = GridBagConstraints.HORIZONTAL;
		gbc_lblDueDate.insets = new Insets(0, 40, 5, 5);
		gbc_lblDueDate.gridx = 0;
		gbc_lblDueDate.gridy = 3;
		jpContent.add(lblDueDate, gbc_lblDueDate);
		
		jtfDueDate = new JTextArea();
		GridBagConstraints gbc_jtfDueDate = new GridBagConstraints();
		gbc_jtfDueDate.insets = new Insets(0, 0, 5, 40);
		gbc_jtfDueDate.fill = GridBagConstraints.BOTH;
		gbc_jtfDueDate.gridx = 1;
		gbc_jtfDueDate.gridy = 3;
		jpContent.add(jtfDueDate, gbc_jtfDueDate);
		
		JLabel jlWeight = new JLabel("Percent Weight: ");
		GridBagConstraints gbc_jlWeight = new GridBagConstraints();
		gbc_jlWeight.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_jlWeight.insets = new Insets(0, 40, 5, 5);
		gbc_jlWeight.gridx = 0;
		gbc_jlWeight.gridy = 4;
		jpContent.add(jlWeight, gbc_jlWeight);
		jlWeight.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		
		jtfWeight = new JTextArea();
		GridBagConstraints gbc_jtfWeight = new GridBagConstraints();
		gbc_jtfWeight.anchor = GridBagConstraints.LINE_START;
		gbc_jtfWeight.insets = new Insets(0, 0, 30, 40);
		gbc_jtfWeight.fill = GridBagConstraints.BOTH;
		gbc_jtfWeight.gridx = 1;
		gbc_jtfWeight.gridy = 4;
		jpContent.add(jtfWeight, gbc_jtfWeight);
		
		//Question Label
		JLabel lblFiles = new JLabel("Assignment Files:");
		GridBagConstraints gbc_lblFiles = new GridBagConstraints();
		gbc_lblFiles.anchor = GridBagConstraints.FIRST_LINE_START;
		gbc_lblFiles.insets = new Insets(0, 40, 5, 5);
		gbc_lblFiles.gridx = 0;
		gbc_lblFiles.gridy = 5;
		jpContent.add(lblFiles, gbc_lblFiles);
		lblFiles.setFont(new Font("Lucida Grande", Font.BOLD, 13));
		
		jpFiles = new JPanel(new GridBagLayout());
		jpFiles.setOpaque(false);
		GridBagConstraints gbc_jpFiles = new GridBagConstraints();
		gbc_jpFiles.insets = new Insets(10, 40, 10, 40);
		gbc_jpFiles.gridwidth = 2;
		gbc_jpFiles.fill = GridBagConstraints.HORIZONTAL;
		gbc_jpFiles.gridx = 0;
		gbc_jpFiles.gridy = 6;
		gbc_jpFiles.anchor = GridBagConstraints.PAGE_START;
		jpContent.add(jpFiles, gbc_jpFiles);
		
		jpSubmission = new JPanel();
		GridBagConstraints gbc_jpSubmission = new GridBagConstraints();
		gbc_jpSubmission.weighty = 1.0;
		gbc_jpSubmission.gridwidth = 2;
		gbc_jpSubmission.insets = new Insets(0, 40, 20, 40);
		gbc_jpSubmission.gridx = 0;
		gbc_jpSubmission.gridy = 7;
		gbc_jpSubmission.anchor = GridBagConstraints.PAGE_START;
		gbc_jpSubmission.fill = GridBagConstraints.HORIZONTAL;
		jpContent.add(jpSubmission, gbc_jpSubmission);
		jpSubmission.setLayout(new BoxLayout(jpSubmission, BoxLayout.PAGE_AXIS));
		
		SpinnerNumberModel weightModel = new SpinnerNumberModel(10.0,0,100,1.0);
		GridBagConstraints c = new GridBagConstraints();
		
	}
	
	private void displayListOfFile(){
		jpFiles.removeAll();
		for(int i=0; i < listOfFilePanel.size(); i++){
			GridBagConstraints c = new GridBagConstraints();
			c.gridy = i;
			c.insets = new Insets(0,0,10,0);
			c.anchor = GridBagConstraints.FIRST_LINE_START;
			jpFiles.add(listOfFilePanel.get(i),c); //add to panel for displaying
			System.out.println(i);
		}
		//empty space at bottom - used to fill the bottom of the page
		//when the list is too short
		JPanel p = new JPanel();
		p.setOpaque(false);
		p.setBackground(Color.WHITE);
		GridBagConstraints c_p = new GridBagConstraints();
		c_p.gridy = listOfFilePanel.size();
		c_p.fill = GridBagConstraints.VERTICAL;
		c_p.weightx=1.0;
		c_p.weighty=1.0;
		jpFiles.add(p,c_p);
		
		jpFiles.revalidate();
	}
	

	
	public void loadViewingAsgm(CmsAssignment asgm, CmsAssignmentSubmission asgmSub){
		this.asgm = asgm;
		this.asgmSub = asgmSub;
		resetAllInput();
	}
	
	public void resetAllInput(){
		jpSubmission.removeAll();
		if(asgm!=null){
			jtfTitle.setText(asgm.getAsgmTitle());
			jtfDescription.setText(asgm.getAsgmDescription());
			
			Date createdDate = new Date(asgm.getCreatedDate().getTime());
			Date avaiDate = new Date(asgm.getAvaiDate().getTime());
			if(avaiDate.getTime() == CmsPresenter.DEFAULT_AVAI_DATE.getTime()){
				jtfPostedDate.setText(CmsPresenter.sdf.format(createdDate));
			}
			else{
				jtfPostedDate.setText(CmsPresenter.sdf.format(avaiDate));
			}
			
			//set due date
			Date dueDate = new Date(asgm.getDueDate().getTime());
			jtfDueDate.setText(CmsPresenter.sdf.format(dueDate));

			
			jtfWeight.setText("" + asgm.getPercentWeight() + "%");
			if(! listOfFilePanel.isEmpty()){
				listOfFilePanel = new ArrayList();
			}
			for(File file : asgm.getListOfFile()){
				listOfFilePanel.add(new FileButton(file));
			}
			displayListOfFile();
			
		}
		else{
			System.err.println("ERROR: null Editting Asgm");
		}
		
		if(asgmSub.getSubFiles().size() > 0){
			jpSubmission.add(new LastSubmissionPanel(asgmSub));
			Date today = new Date();
			if(today.before(asgm.getDueDate())){
				jpSubmission.add(new AsgmSubmissionPanel(true));
			}
		}
		else{
			jpSubmission.add(new LastSubmissionPanel(asgmSub));
			Date today = new Date();
			if(today.before(asgm.getDueDate()) && asgmSub.getGivenPoint() == 0.0){
				jpSubmission.add(new AsgmSubmissionPanel(false));
			}
		}
		jpSubmission.repaint();
		jpSubmission.revalidate();
	}
	
	class FileButton extends JButton{
		
		public File attachedFile;
		
		public FileButton(File file){
			super("+ " + file.getName());
			this.attachedFile = file;
			setForeground(Color.BLUE);
			setOpaque(false);
			setBorder(BorderFactory.createEmptyBorder());
			setCursor(new Cursor(Cursor.HAND_CURSOR));
			addActionListener(new ALDownloadFile(file));
		}
	}
	
	public class AsgmSubmissionPanel extends JPanel{
		
		private JPanel jpFiles;
		private List<FileUploadEntry> listOfFilePanel;
		private JButton jbtSubmit;
		private JLabel lblSubmission;

		public AsgmSubmissionPanel( boolean isResubmit) {
			
			listOfFilePanel = new ArrayList();
			
			setForeground(new Color(230,230,230));
			setOpaque(true);
			setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
			setBackground(Color.WHITE);
			GridBagLayout gridBagLayout = new GridBagLayout();
			setLayout(gridBagLayout);

			
			//_________________________________________________________
			//QUESTION:
			JPanel jpQ = new JPanel();
			jpQ.setOpaque(false);
			GridBagConstraints gbc_jpQ = new GridBagConstraints();
			gbc_jpQ.weightx = 1.0;
			gbc_jpQ.fill = GridBagConstraints.HORIZONTAL;
			gbc_jpQ.gridx = 0;
			gbc_jpQ.gridy = 0;
			add(jpQ, gbc_jpQ);
			GridBagLayout gbl_jpQ = new GridBagLayout();
			jpQ.setLayout(gbl_jpQ);
			
			//Question Label
			lblSubmission = new JLabel("Submission: ");
			lblSubmission.setFont(new Font("Lucida Grande", Font.BOLD, 13));
			GridBagConstraints gbc_lblQuestions = new GridBagConstraints();
			gbc_lblQuestions.insets = new Insets(10, 10, 10, 5);
			gbc_lblQuestions.weightx = 0.05;
			gbc_lblQuestions.fill = GridBagConstraints.HORIZONTAL;
			gbc_lblQuestions.anchor = GridBagConstraints.FIRST_LINE_START;
			gbc_lblQuestions.gridx = 0;
			gbc_lblQuestions.gridy = 0;
			jpQ.add(lblSubmission, gbc_lblQuestions);
			
			//Add Question button
			JButton jbtAddFile = new JButton("+ Add File");
			
			jbtAddFile.setOpaque(false);
			jbtAddFile.setBorder(BorderFactory.createEmptyBorder());
			jbtAddFile.setFont(new Font("Lucida Grande", Font.BOLD, 13));
			jbtAddFile.setForeground(Color.BLUE);
			GridBagConstraints gbc_jbtAddQuestion = new GridBagConstraints();
			gbc_jbtAddQuestion.insets = new Insets(10, 0, 0, 5);
			gbc_jbtAddQuestion.weightx = 0.5;
			gbc_jbtAddQuestion.anchor = GridBagConstraints.FIRST_LINE_START;
			gbc_jbtAddQuestion.gridx = 1;
			gbc_jbtAddQuestion.gridy = 0;
			jpQ.add(jbtAddFile, gbc_jbtAddQuestion);
			
			jbtSubmit = new JButton("Submit");
			jbtSubmit.setFont(jbtSubmit.getFont().deriveFont(Font.BOLD).deriveFont(13.0f));
			jbtSubmit.setPreferredSize(new Dimension(75, 20));
			jbtSubmit.setMinimumSize(new Dimension(75,20));
			jbtSubmit.setBackground(new Color(170,170,170));
			jbtSubmit.setForeground(new Color(30,30,30));
			jbtSubmit.setOpaque(true);
			jbtSubmit.setBorder(BorderFactory.createLineBorder(new Color(30,30,30)));
			GridBagConstraints c = new GridBagConstraints();
			c.insets = new Insets(10, 0, 0, 10);
			c.anchor = GridBagConstraints.FIRST_LINE_END;
			c.gridx = 2;
			c.gridy = 0;
			jpQ.add(jbtSubmit, c);
			
			//Files Panel
			jpFiles = new JPanel();
			jpFiles.setOpaque(false);
			GridBagConstraints gbc_jpQuestions = new GridBagConstraints();
			gbc_jpQuestions.anchor = GridBagConstraints.FIRST_LINE_START;
			gbc_jpQuestions.weighty = 1.0;
			gbc_jpQuestions.fill = GridBagConstraints.HORIZONTAL;
			gbc_jpQuestions.gridx = 0;
			gbc_jpQuestions.gridy = 1;
			add(jpFiles, gbc_jpQuestions);
			jpFiles.setLayout(new GridBagLayout());
			
			//set submit or resubmit
			if(isResubmit){
				lblSubmission.setText("Resubmission: ");
				jbtSubmit.setText("Resubmit");
			}
			else{
				lblSubmission.setText("Submission: ");
				jbtSubmit.setText("Submit");
			}
			
			
			//ACTION LISTENERS:
			jbtAddFile.addActionListener(new AddFileActionListener());
			jbtSubmit.addActionListener(new ALAssignmentSubmission(isResubmit));
		}
		
		private void displayListOfFile(){
			jpFiles.removeAll();
			for(int i=0; i < listOfFilePanel.size(); i++){
				GridBagConstraints c = new GridBagConstraints();
				c.gridy = i;
				c.insets = new Insets(0,10,10,10);
				jpFiles.add(listOfFilePanel.get(i),c); //add to panel for displaying
				System.out.println(i);
			}
			jpFiles.revalidate();
		}

		public boolean validateFileInput(File newFile){
			//compare new file's name to all selected files
			for(FileUploadEntry fe : listOfFilePanel){
				if(fe.getSelectedFile().getName().equals(newFile.getName())){
					String errorMsg = new String("ERROR: Your selected File, "
												+newFile.getName() 
												+ ", is already inserted on the file list");
					JOptionPane.showMessageDialog(CmsPresenter.mainView,errorMsg, "ERROR",JOptionPane.ERROR_MESSAGE);
					return false;
				}
			}
			
			return true;
		}
		
		private class AddFileActionListener implements ActionListener{

			@Override
			public void actionPerformed(ActionEvent e) {
				
				JFileChooser fc = new JFileChooser();
				int returnVal = fc.showOpenDialog(CmsPresenter.mainView);
				if(returnVal == JFileChooser.APPROVE_OPTION){
					File selectedFile = fc.getSelectedFile();
					if(validateFileInput(selectedFile)){
						listOfFilePanel.add(new FileUploadEntry(selectedFile));
						displayListOfFile();
					}
				}
			}
			
		}
		
		public class ALAssignmentSubmission implements ActionListener {

			private boolean isResubmission;
			
			public ALAssignmentSubmission(boolean isResubmission){
				this.isResubmission = isResubmission;
			}

			@Override
			public void actionPerformed(ActionEvent e) {
				if(listOfFilePanel.size() == 0) JOptionPane.showMessageDialog(CmsPresenter.mainView, "ERROR: You have not selected any file to submit!\n\nPlease select at least a file to submit","ERROR",JOptionPane.ERROR_MESSAGE);
				else{
					CmsAssignmentSubmission submission = getAssignmentSubmission();
					List<File> asgmFiles = submission.getSubFiles();
					List<File> newFiles = new ArrayList();
					for(File file : asgmFiles){
						try {
							Files.copy(Paths.get(file.getPath()),
									Paths.get("./AsgmSubFiles/" + file.getName()), 
									StandardCopyOption.REPLACE_EXISTING);
							newFiles.add(new File("./AsgmFiles/" + file.getName()));
						} catch (IOException e1) {
							JOptionPane.showMessageDialog(CmsPresenter.mainView, "System cannot locate this file on your system:\n\n" + file.getName() + "\n\n Post assignment is aborted" );
							return;
						}
					}
					submission.setSubFiles(newFiles);
					
					System.out.println("SUBMISSION:\n" + getAssignmentSubmission());
					
					
					if(isResubmission){
						StudentAssignmentActivities.reSubmitAssignment(getAssignmentSubmission());
					}
					else StudentAssignmentActivities.submitAssignment(getAssignmentSubmission());
					
					StudentAssignmentActivities.getSubmission(CmsPresenter.user.getUsername(), asgm.getAsgmID());
					
					CmsPresenter.mainView.displayAssignmentViewStudentPage(asgm, submission);
				}
			}
		}

		
		public CmsAssignmentSubmission getAssignmentSubmission(){
			int asgmSubID = 0;
			String studentId = CmsPresenter.user.getUsername();
			int asgmID = asgm.getAsgmID();
			List<File> subFiles = new ArrayList();
			for(FileUploadEntry fileEntry : listOfFilePanel){
				subFiles.add(fileEntry.getSelectedFile());
			}
			double givenPoint = 0;
			Date createdDate = new Date();
			CmsAssignmentSubmission asgmSub = new CmsAssignmentSubmission(0,studentId , asgmID, subFiles, createdDate, givenPoint);
			return asgmSub;
		}
		
		public class FileUploadEntry extends JPanel{
			
			private static final int HEIGHT = 50;
			private static final int WIDTH = 450;
			
			private File selectedFile;
			
			private JLabel jlFileName;
			private JButton selectButton;
			private JButton removeButton;
			
			public FileUploadEntry(File file) {
				setBackground(Color.WHITE);
				setOpaque(false);
				setForeground(Color.WHITE);
				
				this.selectedFile = file;
				
				setBackground(Color.WHITE);
				
				GridBagLayout gridBagLayout = new GridBagLayout();
				setLayout(gridBagLayout);
				setOpaque(false);
				setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
				
				JPanel panel = new JPanel();
				panel.setOpaque(false);
				panel.setPreferredSize(new Dimension(WIDTH-20,HEIGHT));
				panel.setMaximumSize(new Dimension(WIDTH-20,HEIGHT));
				panel.setMinimumSize(new Dimension(WIDTH-20,HEIGHT));
				panel.setBorder(BorderFactory.createEmptyBorder());
				GridBagConstraints gbc_panel = new GridBagConstraints();
				gbc_panel.anchor = GridBagConstraints.LINE_START;
				gbc_panel.insets = new Insets(10, 10, 5, 10);
				gbc_panel.fill = GridBagConstraints.HORIZONTAL;
				gbc_panel.gridx = 0;
				gbc_panel.gridy = 0;
				add(panel, gbc_panel);
				GridBagLayout gbl_panel = new GridBagLayout();
				panel.setLayout(gbl_panel);
				
				jlFileName = new JLabel(selectedFile.getName());
				jlFileName.setFont(new Font("Lucida Grande", Font.BOLD, 13));
				GridBagConstraints gbc_jlQuestionNum = new GridBagConstraints();
				gbc_jlQuestionNum.anchor = GridBagConstraints.LINE_START;
				gbc_jlQuestionNum.insets = new Insets(0, 0, 0, 5);
				gbc_jlQuestionNum.fill = GridBagConstraints.HORIZONTAL;
				gbc_jlQuestionNum.gridx = 0;
				gbc_jlQuestionNum.gridy = 0;
				gbc_jlQuestionNum.gridwidth = 2;
				panel.add(jlFileName, gbc_jlQuestionNum);
				
				selectButton = new JButton("Reselect File");
				selectButton.setForeground(Color.BLUE);
				selectButton.setOpaque(false);
				selectButton.setBorder(BorderFactory.createEmptyBorder());
				GridBagConstraints gbc_jbtClear = new GridBagConstraints();
				gbc_jbtClear.anchor = GridBagConstraints.LINE_END;
				gbc_jbtClear.weightx = 1.0;
				gbc_jbtClear.insets = new Insets(0, 0, 0, 30);
				gbc_jbtClear.gridx = 0;
				gbc_jbtClear.gridy = 1;
				panel.add(selectButton, gbc_jbtClear);
				
				removeButton = new JButton("Remove");
				removeButton.setForeground(Color.BLUE);
				removeButton.setOpaque(false);
				removeButton.setBorder(BorderFactory.createEmptyBorder());
				GridBagConstraints gbc_btnRemove = new GridBagConstraints();
				gbc_btnRemove.anchor = GridBagConstraints.LINE_END;
				gbc_btnRemove.gridx = 1;
				gbc_btnRemove.gridy = 1;
				panel.add(removeButton, gbc_btnRemove);
				
				
				//ACTION LISTENER:
				selectButton.addActionListener(new ActionListener(){

					@Override
					public void actionPerformed(ActionEvent e) {
						JFileChooser fc = new JFileChooser();
						int returnVal = fc.showOpenDialog(CmsPresenter.mainView);
						if(returnVal == JFileChooser.APPROVE_OPTION){
							
							if(validateFileInput(fc.getSelectedFile())){
								selectedFile = new File(fc.getSelectedFile().getPath());
								jlFileName.setText(selectedFile.getName());
							}
						}
					}
					
				});
				
				removeButton.addActionListener(new ActionListener(){

					@Override
					public void actionPerformed(ActionEvent e) {
						listOfFilePanel.remove(FileUploadEntry.this);
						displayListOfFile();
					}
					
				});
			}
			
			public File getSelectedFile(){
				return this.selectedFile;
			}
		}
		
		
		@Override
		protected void paintComponent(Graphics g){
			super.paintComponent(g);
			g.fillRoundRect(10, 10, this.getWidth()-20, this.getHeight()-20, 10, 10);
		}		
	}
}
